import 'dart:convert';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
import 'package:html_unescape/html_unescape.dart';

class StringUtils {
  static String toMD5(String data) {
    var content = new Utf8Encoder().convert(data);
    var digest = md5.convert(content);
    return hex.encode(digest.bytes);
  }

  static String urlDecoder(String data) {
    return data == null ? null : HtmlUnescape().convert(data);
  }

  static String removeHtmlLabel(String data) {
    return data?.replaceAll(RegExp('<[^>]+>'), '');
  }

  static bool isEmpty(String targetStr){
    if(targetStr==null||targetStr.isEmpty){
      return true;
    }
    return false;
  }

  static String appendSkill(List<dynamic> skills) {
    if (skills == null || skills.isEmpty) {
      return "";
    }
    String appendSkills = "";
    for (int i = 0; i < skills.length; i++) {
      if (i == skills.length - 1) {
        appendSkills += skills[i];
      } else {
        appendSkills += skills[i] + "/";
      }
    }
    return appendSkills;
  }

  static formatNullStr(String info){
    return info??"";
  }
}
